package com.ssy.lingxi.contract.controller.mobile;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.contract.model.vo.sign.request.AutoSignRequest;
import com.ssy.lingxi.contract.model.vo.sign.request.OrderSettleSignDetailRequest;
import com.ssy.lingxi.contract.model.vo.sign.request.OrderSettleSignRequest;
import com.ssy.lingxi.contract.model.vo.sign.request.SignContractPreOrderRequest;
import com.ssy.lingxi.contract.model.vo.sign.response.OrderSettleSignDetailResponse;
import com.ssy.lingxi.contract.model.vo.sign.response.SignContractCreateResponse;
import com.ssy.lingxi.contract.model.vo.sign.response.SignCreateResponse;
import com.ssy.lingxi.contract.service.IOrderSignatureService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @menu APP - 订单合同签署
 * @author yzc
 * @version 2.0.0
 * @date 2021/1/27
 */
@RestController
@RequestMapping("/order/mobile/contract/sign")
public class MobileOrderContractSignController extends BaseController {

    @Resource
    private IOrderSignatureService orderSignatureService;

    /**
     * 订单结算-生成电子合同
     * @param request 请求参数 请求参数
     * @return 返回结果
     */
    @PostMapping(value = "/settlement/signContractCreate")
    public Wrapper<SignContractCreateResponse> settlementPreOrderSignContractCreate(@RequestBody @Validated SignContractPreOrderRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return orderSignatureService.preOrderSignContractCreate(request, sysUser);
    }

    /**
     * 订单结算-合同签署
     * @param request 请求参数 请求参数
     * @return 返回结果
     */
    @PostMapping(value = "/settlement/oneStepSign")
    public Wrapper<SignCreateResponse> settlementOrderSettleSign(@RequestBody @Validated OrderSettleSignRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return orderSignatureService.settlementOrderSettleSign(request, sysUser);
    }

    /**
     * 采购订单新增-生成电子合同
     * @param request 请求参数 请求参数
     * @return 返回结果
     */
    @PostMapping(value = "/procurement/signContractCreate")
    public Wrapper<SignContractCreateResponse> procurementSignContractCreate(@RequestBody @Validated SignContractPreOrderRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return orderSignatureService.preOrderSignContractCreate(request, sysUser);
    }

    /**
     * 采购订单新增-合同签署
     * @param request 请求参数 请求参数
     * @return 返回结果
     */
    @PostMapping(value = "/procurement/oneStepSign")
    public Wrapper<SignCreateResponse> procurementOrderSettleSign(@RequestBody @Validated OrderSettleSignRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return orderSignatureService.settlementOrderSettleSign(request, sysUser);
    }

    /**
     * 订单签署查询结果
     * @param request 请求参数 请求参数
     * @return 返回结果
     */
    @GetMapping(value = "/orderSettleSignDetail")
    public Wrapper<OrderSettleSignDetailResponse> orderSettleSignDetail(OrderSettleSignDetailRequest request) {
        return orderSignatureService.orderSettleSignDetail(request);
    }

    /**
     * 采购确认电子合同-合同签署
     * @param request 请求参数 请求参数
     * @return 返回结果
     */
    @PostMapping(value = "/procurement/sign")
    public Wrapper<Void> procurementSign(@RequestBody @Validated AutoSignRequest request) {
        UserLoginCacheDTO sysUser = getSysUser();
        return orderSignatureService.procurementSign(request, sysUser);
    }
}
